/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;


import com.cashmate.hibernate.dao.BorrowerDAO;
import com.cashmate.hibernate.dao.LoanverificationDAO;
import com.cashmate.hibernate.pojo.Loanverification;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Lee
 */
public class GetLoanapps_CI extends ActionSupport {

    //private BorrowerDAO bord = (BorrowerDAO) ServletActionContext.getServletContext().getAttribute("borrowerDAO");
    private LoanverificationDAO lvd = (LoanverificationDAO) ServletActionContext.getServletContext().getAttribute("loanverificationDAO");
    private String[] laciList;
    private List<String> laciList1;

    public String[] getLaciList() {
        return laciList;
    }

    @Action(value = "/get-la-ci", results = {
        @Result(name = "input", location = "/loanapplication.jsp"),
        @Result(name = "success", location = "/loanapplication.jsp"),
        @Result(name = "error", location = "/loanapplication.jsp")
    })
    @Override
    public String execute() {
        try {
//            System.out.println("yes");
            laciList1 = new ArrayList<String>();
            List<Loanverification> llaci = lvd.getAll();
            List<Loanverification> llacinoci = new ArrayList<Loanverification>();
            for(int i = 0; i < llaci.size(); i++){
                if(!llaci.get(i).getWithci().equals("y")){
                    llacinoci.add(llaci.get(i));
//                    System.out.println(llaci.get(i).getLoanverificationid());
                }
            }

            if (!llacinoci.isEmpty()) {
                for (int i = 0; i < llacinoci.size(); i++) {

                    String id = llacinoci.get(i).getDocumentno();
                    String borcode = llacinoci.get(i).getBorrowers().getBorrowercode();
                    String name = llacinoci.get(i).getBorrowers().getCompletename();

                    String info = id + " " + borcode + " " + name;
//                    System.out.println(info);
                    laciList1.add(info);
                }

                laciList = laciList1.toArray(new String[laciList1.size()]);
            }
        } catch (Exception e) {
            return ERROR;
        }
        return SUCCESS;

    }
}
